001 /*
002 * Copyright 2005 Stephen J. McConnell.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
013 * implied.
014 *
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019 package net.dpml.transit.info;
020
021 import net.dpml.lang.AbstractDirective;
022
023 /**
024 * The CodeBaseDirective is immutable datastructure used to
025 * describe a codebase.
026 *
027 * @author <a href="http://www.dpml.net">Digital Product Meta Library</a>
028 * @version 1.0.1
029 */
030 public class TransitDirective extends AbstractDirective
031 {
032 /**
033 * Classic configuration profile.
034 */
035 public static final TransitDirective CLASSIC_PROFILE = createClassicProfile();
036
037 private final ProxyDirective m_proxy;
038 private final CacheDirective m_cache;
039
040 /**
041 * Creation of a new codebase descriptor.
042 * @param proxy the proxy configuration
043 * @param cache the cache configuration
044 * @exception NullPointerException if the cache configuration arguments is null
045 */
046 public TransitDirective( ProxyDirective proxy, CacheDirective cache )
047 throws NullPointerException
048 {
049 if( null == cache )
050 {
051 throw new NullPointerException( "cache" );
052 }
053
054 m_proxy = proxy;
055 m_cache = cache;
056 }
057
058 /**
059 * Return the cache configuration directive.
060 *
061 * @return the cache directive
062 */
063 public CacheDirective getCacheDirective()
064 {
065 return m_cache;
066 }
067
068 /**
069 * Return the proxy configuration.
070 *
071 * @return the proxy directive (possibly null)
072 */
073 public ProxyDirective getProxyDirective()
074 {
075 return m_proxy;
076 }
077
078 /**
079 * Test if the supplied object is equal to this object.
080 * @param other the object to evaluate
081 * @return true if this object is equal to the supplied object
082 */
083 public boolean equals( Object other )
084 {
085 if( super.equals( other ) && ( other instanceof TransitDirective ) )
086 {
087 TransitDirective directive = (TransitDirective) other;
088 if( !equals( m_proxy, directive.m_proxy ) )
089 {
090 return false;
091 }
092 else
093 {
094 return equals( m_cache, directive.m_cache );
095 }
096 }
097 else
098 {
099 return false;
100 }
101 }
102
103 /**
104 * Compute the instance hashcode value.
105 * @return the hashcode
106 */
107 public int hashCode()
108 {
109 int hash = super.hashCode();
110 hash ^= hashValue( m_proxy );
111 hash ^= hashValue( m_cache );
112 return hash;
113 }
114
115 private static TransitDirective createClassicProfile()
116 {
117 HostDirective[] hosts = new HostDirective[4];
118 hosts[0] =
119 new HostDirective(
120 "dpml", 40, "http://repository.dpml.net/classic", null, null, null,
121 true, false, "classic", null, null );
122 hosts[1] =
123 new HostDirective(
124 "ibiblio", 70, "http://www.ibiblio.org/maven", null, null, null,
125 true, false, "classic", null, null );
126 hosts[2] =
127 new HostDirective(
128 "m2", 100, "http://www.ibiblio.org/maven2", null, null, null,
129 true, false, "modern", null, null );
130 hosts[3] =
131 new HostDirective(
132 "apache", 140, "http://www.apache.org/dist/java-repository", null, null, null,
133 true, false, "classic", null, null );
134
135 CacheDirective cache =
136 new CacheDirective(
137 CacheDirective.CACHE_PATH,
138 CacheDirective.CACHE_LAYOUT,
139 CacheDirective.LOCAL_PATH,
140 CacheDirective.LOCAL_LAYOUT,
141 CacheDirective.EMPTY_LAYOUTS,
142 hosts );
143 return new TransitDirective( null, cache );
144 }
145
146 }